package com.by.interceptor;

import com.by.auto.TokenInterceptorProperties;
import com.by.token.TokenTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

public class TokenWebConfig implements WebMvcConfigurer {

    TokenInterceptorProperties properties;
    TokenTemplate tokenTemplate;

    public TokenWebConfig(TokenInterceptorProperties properties, TokenTemplate tokenTemplate) {
        this.properties = properties;
        this.tokenTemplate = tokenTemplate;

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor(tokenTemplate))
                .addPathPatterns(properties.getPathPatterns())//拦截的请求
                .excludePathPatterns(properties.getExcludePathPatterns());//不拦截的请求
    }
}
